#pragma once

#include <QLineEdit>
#include <QListWidget>
#include <QPropertyAnimation>
#include <QTimer>
#include <QWidget>

class MdxEngin;

class SearchOverlay : public QWidget {
    Q_OBJECT
public:
    explicit SearchOverlay(MdxEngin* dict, QWidget* parent = nullptr);
    void toggle();

signals:
    void searchSubmitted(const QString& text);

protected:
    void focusOutEvent(QFocusEvent* e) override;
    bool event(QEvent* e) override;

private slots:
    void showWithSlide();
    void hideWithSlide();
    void onTextChanged(const QString& text);
    void onItemActivated(QListWidgetItem* item);

private:
    QRect targetGeometry() const;
    void applyStyle();

private:
    MdxEngin* m_dict = nullptr;
    QLineEdit* m_input = nullptr;
    QListWidget* m_list = nullptr;
    QPropertyAnimation* m_anim = nullptr;
    bool m_showing = false;
    QElapsedTimer m_gap;
};
